package net.wanho.service.impl;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.authority.AuthorityUtils;
import org.springframework.security.core.userdetails.User;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.core.userdetails.UserDetailsService;
import org.springframework.security.core.userdetails.UsernameNotFoundException;
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
import org.springframework.stereotype.Service;

/**
 * Author：汤小洋
 * Date：2023-11-13 11:34
 * Description：<描述>
 */
@Service
public class MyUserDetailsService implements UserDetailsService {

    @Autowired
    private BCryptPasswordEncoder passwordEncoder;

    @Override
    public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException {
        // TODO: 2023-11-13 11:34 根据用户名查询用户信息
        // SysUser user = userMapper.selectByUsername(username);
        // user.getUsername();
        // user.getPassword();
        // user.getPermissions();

        User user = new User(
                username,
                passwordEncoder.encode("admin"),
                AuthorityUtils.createAuthorityList("sys:user:list", "sys:user:edit", "ROLE_role_admin")
        );
        return user;
    }

}
